package com.situ.mall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.situ.mall.entity.Product;
import com.situ.mall.mapper.ProductMapper;
import com.situ.mall.service.IProductService;
import com.situ.mall.util.LayUITableResult;

@Service
public class ProductServiceImpl implements IProductService {
	@Autowired
	private ProductMapper productMapper;

	@Override
	public List<Product> selectAll() {
//		ProductExample productExample = new ProductExample();
//		Criteria criteria = productExample.createCriteria();
//		criteria.andNameLike("%Apple%");
//		criteria.andStockGreaterThanOrEqualTo(2000);
//		return productMapper.selectByExample(productExample);
		
		return productMapper.selectAll();
	}

	@Override
	public LayUITableResult selectByPage(Integer page, Integer limit) {
		int offset = (page - 1) * limit;
		List<Product> list = productMapper.selectByPage(offset, limit);
		
		int count = productMapper.selectTotalCount();
		
		return LayUITableResult.ok(count, list);
	}

	@Override
	public void insert(Product product) {
		productMapper.insert(product);
	}

	@Override
	public List<Product> selectByCategoryId(Integer categoryId) {
		return productMapper.selectByCategoryId(categoryId);
	}

	@Override
	public Product getProductDetailPage(Integer id) {
		return productMapper.selectByPrimaryKey(id);
	}

}
